package com.ruyuan2020.im.design.ChainOfResponsibilityPattern.use;

import com.ruyuan2020.im.design.ChainOfResponsibilityPattern.use.request.PaymentRequest;
import com.ruyuan2020.im.design.ChainOfResponsibilityPattern.use.request.Request;

public class PaymentHandler extends Handler{
    @Override
    public void handleRequest(Request request) {
        if (request instanceof PaymentRequest) {
            PaymentRequest paymentRequest = (PaymentRequest) request;
            if (paymentRequest.getPayment() != null && paymentRequest.getPayment().isAvailable()) {
                System.out.println("支付验证通过！");
            } else {
                System.out.println("支付验证失败！");
                return; // 验证失败，不再传递请求
            }
        }
        // 如果本处理者处理后请求未被结束，则继续传递
        if (successor != null) {
            successor.handleRequest(request);
        }
    }
}
